/**
* Copyright (c) 2016-2100 yunclouds
*/
package com.yunqian.web;

import com.yunqian.common.CurrentUser;
import com.yunqian.jwt.JwtUser;
import com.yunqian.redot.constant.Operation;
import com.yunqian.redot.constant.OperationMenus;
import com.yunqian.redot.domain.InformationWords;
import com.yunqian.redot.domain.view.InformationWordsDetails;
import com.yunqian.redot.service.InformationWordsDetailsService;
import com.yunqian.redot.service.InformationWordsService;
import com.yunqian.redot.service.OperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * Describe: 咨询留言控制器
 *
 * @author zsy
 * 2018-09-29 15:54:49
 */
 @RestController
 @RequestMapping("/api/informationWords")
public class InformationWordsController {

     @Autowired
     private InformationWordsService informationWordsService;
     @Autowired
     private InformationWordsDetailsService informationWordsDetailsService;
     @Autowired
     private OperationLogService operationLogService;

    /**
     * 获取分页
     *
     * @param params
     * @return
     */
    @PostMapping("/pagination")
    public Page<InformationWordsDetails> pagination(@RequestBody Map<String, Object> params) {
        return informationWordsDetailsService.pagination(params);
    }

    /**
     * 设置精选
     *
     * @param id         待更新id
     * @param modifyData 待更新的数据
     * @return
     */
    @PutMapping("/{id}")
    public InformationWords update(@PathVariable("id") Long id, @RequestBody Map<String, Object> modifyData, @CurrentUser JwtUser user) {
        InformationWords informationWords = informationWordsService.update(id, modifyData);
        if(informationWords.getAsBrilliant() == 1){
            operationLogService.save(OperationMenus.NEWS_MESSAGE, Operation.SET_CHOICENESS, user.getId());
        }else {
            operationLogService.save(OperationMenus.NEWS_MESSAGE, Operation.CANCLE_CHOICENESS, user.getId());
        }
        return informationWords;
    }
}
